<!--头部公共部分-->
{include file="common/header" /}
<style>
    input::-webkit-outer-spin-button,
    input::-webkit-inner-spin-button {
        -webkit-appearance: none;
    }
    input[type="number"] {
        -moz-appearance: textfield;
    }
</style>
<div class="x-nav">
      <span class="layui-breadcrumb">
          <a>首页</a><a>我的客户</a><a><cite>编辑资料</cite></a>
	  </span>
    <a class="layui-btn layui-btn-xs layui-btn-small" style="float:right;margin-top: 10px;"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh"></i> </a>
</div>
<div style="padding:15px;">
    <form class="layui-form" style="width: 970px;">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">省/市/区</label>
                <div class="layui-input-inline">
                    <input type="text" name="address" placeholder="请输入省/市/区" value="{$student.address}" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>书店名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" lay-verify="required" value="{$student.student_name}" placeholder="请输入书店名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>联系方式</label>
                <div class="layui-input-inline">
                    <input type="number" name="phone" lay-verify="required" value="{$student.phone}" placeholder="请输入联系方式" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">来源渠道</label>
                <div class="layui-input-inline">
                    <select name="channel" lay-search="" lay-filter="channel">
                        <option value="">请选渠道</option>
                        {volist name="data[2]" id="v"}
                        <option value="{$v.id}" {if $student.channel == $v.id}selected{/if}>{$v['name']}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">意向级别</label>
                <div id="test-rate-dome5"></div>
                <input type="hidden" id="grade" name="intentional_grade" value="{$student.intentional_grade}"/>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>渠道专员</label>
                <div class="layui-input-inline">
                    {if $current_type == 5}
                    <select name="user_id" lay-filter="user_id" disabled>
                        {volist name="users" id="user"}
                        <option value="{$user.id}" {if $student.user_id == $user.id}selected{/if}>{$user['name']}</option>
                        {/volist}
                    </select>
                    {else/}
                    <select name="user_id" lay-search="" lay-verify="required"  lay-filter="user_id">
                        <option value="">请选择渠道专员</option>
                        {volist name="users" id="user"}
                        <option value="{$user.id}" {if $student.user_id == $user.id}selected{/if}>{$user['name']}</option>
                        {/volist}
                    </select>
                    {/if}
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">手机号码</label>
                <div class="layui-input-inline">
                    <input type="number" name="guardian_phone" value="{$student.guardian_phone}" placeholder="请输入手机号码" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">跟进对象</label>
                <div class="layui-input-inline">
                    <input type="text" name="follow_up_object" value="{$student.follow_up_object}" placeholder="请输入跟进对象" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">更多联系人</label>
                <div class="layui-input-inline">
                    <input type="number" name="other_phone" value="{$student.other_phone}" placeholder="请输入更多联系人" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">微信账号</label>
                <div class="layui-input-inline">
                    <input type="text" name="weixin" value="{$student.weixin}" placeholder="请输入微信" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">QQ账号</label>
                <div class="layui-input-inline">
                    <input type="text" name="qq" value="{$student.qq}" placeholder="请输入QQ" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注信息</label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="请输入备注信息" class="layui-textarea">{$student.remark}</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">详细地址</label>
            <div class="layui-input-block">
                <textarea name="detailed_address" placeholder="请输入详细地址" class="layui-textarea">{$student.detailed_address}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="id" value="{$student.id}">
                <input class="layui-btn" lay-submit lay-filter="form" value="保存" readonly>
                <a class="layui-btn layui-btn-primary" href="/admin/Customer/information/id/{$student.id}/status/1">返回</a>
            </div>
        </div>
    </form>
</div>
<!--底部公共部分-->
{include file="common/footer" /}
<script>
    function kehu() {
        let name = document.getElementById("name").value;
        $('#student_name').val(name);
    }
    layui.use(['element', 'rate', 'jquery','form','laydate','layer'], function () {
        var $ = layui.$,
            layer = layui.layer,
            rate = layui.rate,
            form = layui.form,
            element = layui.element,
            laydate = layui.laydate,
            jquery = layui.jquery;

        let grade = $("#grade").val();

        //自定义文本
        rate.render({
            elem: '#test-rate-dome5'
            ,value: grade
            ,text: false
            ,setText: function(value){ //自定义文本的回调
                let arrs = {
                    '1': '1'
                    ,'2': '2'
                    ,'3': '3'
                    ,'4': '4'
                    ,'5': '5'
                };
                console.log(arrs[value]);
                $("#grade").val(arrs[value]);
            }
        })

        //日期
        laydate.render({
            elem: '#date'
            ,trigger: 'click'
        });

        //监听提交
        form.on('submit(form)', function (data) {
            console.log(data);
            //发异步，把数据提交给php
            var field = data.field;
            var isLoad;
            $.ajax({
                url: '{:url("Customer/edit")}',
                method: "post",
                data: field,
                success: function (result) {
                    layer.msg(result.msg);
                    if (result.code === 0) {
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            parent.location.reload();
                        }, 2000);
                    }
                },
                complete: function () {
                    layer.close(isLoad)
                },
                error: function (error) {
                    console.log(error)
                }
            });
            return false;
        });
    });
</script>